using System;
using System.Collections.Generic;
using System.Text;
using System.Security;
using System.Runtime.InteropServices;

namespace InfiniTec.Security
{
    static class Util
    {
        public const int MaxPasswordLength = 256;
        public const int MaxUsernameLength = 256;

        public static SecureString LPStringToSecureString(IntPtr input, int size)
        {
            int index;
            char c;
            SecureString result;

            result = new SecureString();

            index = 0;
            while (index < size)
            {
                c = (char) Marshal.ReadInt16(input, sizeof(char) * index);
                if (c == 0) break;
                result.AppendChar(c);
                index++;
            }
            result.MakeReadOnly();

            return result;
        }
    }
}
